package com.cgc.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.cgc.dao.IEmpDao;
import com.cgc.entity.Dept;
import com.cgc.entity.Emp;

@Component
public class EmpDaoImpl extends BaseDaoImpl<Emp> implements IEmpDao<Emp> {
	@Override
	public DetachedCriteria getDetachedCriteria(Emp emp){
		DetachedCriteria dc = DetachedCriteria.forClass(Emp.class);
		/*if(dept!=null){
			if(null!=dept.getName() && dept.getName().trim().length()>0){
				dc.add(Restrictions.like("d_name", dept.getName(),MatchMode.ANYWHERE));
			}
			if(null!=dept.getTele() && dept.getTele().trim().length()>0){
				dc.add(Restrictions.like("d_address", dept.getTele(),MatchMode.ANYWHERE));
			}
		}
	*/
		return dc;
		
	}

	@Override
	public Emp checkUser(String username, String pwd) {
		String hql ="from Emp where username=? and pwd=?";
		List<Emp> list =(List<Emp>) this.getHibernateTemplate().find(hql, username,pwd);
		if(list.size()>0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updatePwd(Integer id, String newPwd) {
	   String hql="update Emp set pwd=? where id=?";
	   this.getHibernateTemplate().bulkUpdate(hql, newPwd,id);
		
	}
}
